package com.fr.chart.plot;

import com.fr.base.background.IntervalColorBackground;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.Axis;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.core.glyph.ValueAxisGlyph;
import com.fr.chart.core.glyph.XYScatterPlotGlyph;
import com.fr.chart.legend.LineMarkerIcon;
import com.fr.data.ChartData;
import com.fr.data.impl.ReportChartData;
import com.fr.util.Utils;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

public class XYScatterPlot extends Plot
{
  private static final long serialVersionUID = 5947464168434538499L;
  private ValueAxis xAxis = new ValueAxis();
  private ValueAxis yAxis;
  private boolean showLine = true;
  private boolean showMarker = true;
  private boolean bgStagger = false;
  private Color bgColor = Color.white;

  public XYScatterPlot()
  {
    this.xAxis.setPosition(3);
    this.yAxis = new ValueAxis();
  }

  public PlotGlyph createPlotGlyph(ChartData paramChartData)
  {
    XYScatterPlotGlyph localXYScatterPlotGlyph = new XYScatterPlotGlyph();
    paramChartData = create65Data4New(paramChartData);
    install4PlotGlyph(localXYScatterPlotGlyph, paramChartData);
    createAxisGlyph(localXYScatterPlotGlyph, paramChartData);
    return localXYScatterPlotGlyph;
  }

  public void install4PlotGlyph(XYScatterPlotGlyph paramXYScatterPlotGlyph, ChartData paramChartData)
  {
    super.install4PlotGlyph(paramXYScatterPlotGlyph, paramChartData);
    paramXYScatterPlotGlyph.setShowLine(this.showLine);
    paramXYScatterPlotGlyph.setShowMarker(this.showMarker);
  }

  private void createAxisGlyph(PlotGlyph paramPlotGlyph, ChartData paramChartData)
  {
    XYScatterPlotGlyph localXYScatterPlotGlyph = (XYScatterPlotGlyph)paramPlotGlyph;
    ValueAxisGlyph localValueAxisGlyph1 = new ValueAxisGlyph(this.xAxis);
    localXYScatterPlotGlyph.setXAxisGlyph(localValueAxisGlyph1);
    initXAxisGlyph(localValueAxisGlyph1, paramChartData);
    localXYScatterPlotGlyph.axisExtends(localValueAxisGlyph1);
    ValueAxisGlyph localValueAxisGlyph2 = new ValueAxisGlyph(this.yAxis);
    localXYScatterPlotGlyph.setYAxisGlyph(localValueAxisGlyph2);
    localValueAxisGlyph2.initMinMaxValue(getMinValueFromData(paramChartData), getMaxValueFromData(paramChartData));
    if (this.bgStagger)
    {
      IntervalColorBackground localIntervalColorBackground = new IntervalColorBackground();
      localIntervalColorBackground.setColor(this.bgColor);
      localIntervalColorBackground.setPosition(this.yAxis.getPosition());
      localXYScatterPlotGlyph.getInfo().setBackground(localIntervalColorBackground);
    }
  }

  private void initXAxisGlyph(ValueAxisGlyph paramValueAxisGlyph, ChartData paramChartData)
  {
    double d1 = 0.0D;
    double d2 = 0.0D;
    for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
    {
      String str = "";
      if (paramChartData.getCategoryLabel(i) != null)
        str = paramChartData.getCategoryLabel(i).toString();
      double d4 = 0.0D;
      Number localNumber = Utils.string2Number(str);
      if (localNumber != null)
        d4 = localNumber.doubleValue();
      if (i == 0)
      {
        d1 = d4;
        d2 = d4;
      }
      else
      {
        d1 = Math.min(d1, d4);
        d2 = Math.max(d2, d4);
      }
    }
    double d3 = Axis.calculateIncrement(d1, d2);
    paramValueAxisGlyph.initMinMaxValue(d1 - d3, d2 + d3);
  }

  protected LineMarkerIcon getLineMarkerIconByIndex(int paramInt)
  {
    return getLineMarkerIconByIndex4Line(paramInt);
  }

  protected boolean showLegendLine()
  {
    return this.showLine;
  }

  protected boolean showLegendMarker()
  {
    return this.showMarker;
  }

  public void setYAxis(ValueAxis paramValueAxis)
  {
    this.yAxis = paramValueAxis;
  }

  public ValueAxis getYAxis()
  {
    return this.yAxis;
  }

  public ValueAxis getXAxis()
  {
    return this.xAxis;
  }

  public boolean isShowLine()
  {
    return this.showLine;
  }

  public void setShowLine(boolean paramBoolean)
  {
    this.showLine = paramBoolean;
  }

  public boolean isShowMarker()
  {
    return this.showMarker;
  }

  public void setShowMarker(boolean paramBoolean)
  {
    this.showMarker = paramBoolean;
  }

  public void setBgStagger(boolean paramBoolean)
  {
    this.bgStagger = paramBoolean;
  }

  public boolean getBgStagger()
  {
    return this.bgStagger;
  }

  public void setBgColor(Color paramColor)
  {
    this.bgColor = paramColor;
  }

  public Color getBgColor()
  {
    return this.bgColor;
  }

  public ChartData create65Data4New(ChartData paramChartData)
  {
    int i = paramChartData.getSeriesCount();
    int j = paramChartData.getCategoryLabelCount();
    int k = 0;
    for (int l = 0; l < j; ++l)
    {
      Object localObject = paramChartData.getCategoryLabel(l);
      Number localNumber = Utils.objectToNumber(localObject, true);
      if (localNumber == null)
      {
        k = 1;
        break;
      }
    }
    if (k != 0)
    {
      Object[] arrayOfObject2;
      int i2;
      Object[] arrayOfObject1 = new Object[j];
      for (int i1 = 0; i1 < j; ++i1)
        if (i == 1)
          arrayOfObject1[i1] = new Integer(i1 + 1);
        else
          arrayOfObject1[i1] = paramChartData.getValueAt(0, i1);
      if (i == 1)
      {
        arrayOfObject2 = new Object[1];
        arrayOfObject2[0] = paramChartData.getSeriesLabel(0);
      }
      else
      {
        arrayOfObject2 = new Object[i - 1];
        for (i2 = 1; i2 < i; ++i2)
          arrayOfObject2[(i2 - 1)] = paramChartData.getSeriesLabel(i2);
      }
      ArrayList localArrayList1 = new ArrayList();
      ArrayList localArrayList2 = new ArrayList();
      for (int i3 = (i == 1) ? 0 : 1; i3 < i; ++i3)
      {
        localArrayList2 = new ArrayList();
        for (int i4 = 0; i4 < j; ++i4)
          localArrayList2.add(paramChartData.getValueAt(i3, i4));
        localArrayList1.add(localArrayList2.toArray());
      }
      Object[][] arrayOfObject = (Object[][])localArrayList1.toArray(new Object[arrayOfObject2.length][]);
      paramChartData = new ReportChartData(arrayOfObject1, arrayOfObject2, arrayOfObject);
    }
    return paramChartData;
  }

  public boolean match4GUI(Plot paramPlot)
  {
    return ((super.match4GUI(paramPlot)) && (((XYScatterPlot)paramPlot).showLine == this.showLine) && (((XYScatterPlot)paramPlot).showMarker == this.showMarker));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if ("XYScatterAttr".equals(str1))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("showLine")) != null)
          setShowLine(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("showMarker")) != null)
          setShowMarker(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("bgStagger")) != null)
          setBgStagger(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("bgColor")) != null)
          setBgColor(new Color(Integer.parseInt(str2), true));
      }
      else if ("XAxis".equals(str1))
      {
        this.xAxis = ((ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
      }
      else if ("YAxis".equals(str1))
      {
        this.yAxis = ((ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Plot");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("XYScatterAttr").attr("showLine", this.showLine).attr("showMarker", this.showMarker).attr("bgStagger", this.bgStagger);
    if (this.bgColor != null)
      paramXMLPrintWriter.attr("bgColor", this.bgColor.getRGB());
    paramXMLPrintWriter.end();
    if (this.xAxis != null)
    {
      paramXMLPrintWriter.startTAG("XAxis");
      this.xAxis.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.yAxis != null)
    {
      paramXMLPrintWriter.startTAG("YAxis");
      this.yAxis.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof XYScatterPlot))
      return false;
    XYScatterPlot localXYScatterPlot = (XYScatterPlot)paramObject;
    if (!(super.equals(localXYScatterPlot)))
      return false;
    if (localXYScatterPlot.getBgStagger() != getBgStagger())
      return false;
    if (localXYScatterPlot.isShowLine() != isShowLine())
      return false;
    if (localXYScatterPlot.isShowMarker() != isShowMarker())
      return false;
    if (!(Equals.equals(localXYScatterPlot.getXAxis(), getXAxis())))
      return false;
    if (!(Equals.equals(localXYScatterPlot.getYAxis(), getYAxis())))
      return false;
    return (Equals.equals(localXYScatterPlot.getBgColor(), getBgColor()));
  }
}